package com.cskaoyan._14network._04test._02feedback;

import java.io.*;
import java.net.Socket;

/**
 * @author Macro_Ray
 * @since 2024/3/26 10:19
 */
// 客户端：发送一条数据，接收服务端反馈的信息并打印
public class Client {
    public static void main(String[] args) throws IOException {
        // 1.创建客户端Socket
        Socket socket = new Socket("127.0.0.1",10086);

        // 2.写出数据
        String str = "桀桀桀，天下第一";
        OutputStream os = socket.getOutputStream();
        os.write(str.getBytes());

        // 写出结束标记
        socket.shutdownOutput();

        // 3.读入反馈信息
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        int b =0;
        while((b = br.read())!= -1) {
            System.out.print((char) b);
        }

        // 4.释放资源
        os.close();
        socket.close();

    }
}
